<?php
namespace App\Api\Application;


use App\Common as com;
use App\Api as nameApi;
use App\Api\Application\ApplyToken as nameApplyToken;
use App\Common\Server\Api as nameServerApi;
use App\Common\Server\Api\Gateway as nameGateway;

class ApplyTokens extends nameApi\Application\Base {

	public bool $tokenConfig_IsNeedToken = false;

	/*
	protected array $verifyRules = [
	   'id' => 'required|numeric',
	   'ids' => 'required|array',
	];
	*/

	/*
	protected function _checkAuth( nameServerApi\Lib\ApplicationParamDto $apiRequest ) {
		//
		return true;
	}
	*/

	/**
	 * 执行api
	 * @param nameGateway\ApiRequest $apiRequest
	 * @param nameServerApi\Lib\ApplicationParamDto $apiParamDto
	 * @return com\Server\Api\Gateway\ApiResponse|array
	 * @throws
	 */
	protected function _excApi( nameGateway\ApiRequest $apiRequest, nameServerApi\Lib\ApplicationParamDto $apiParamDto ):com\Server\Api\Gateway\ApiResponse|array {
		// @TODO :: [待增]每次使用后自动延长时间。增加一个延长值
		$tokenObj = com\Cla\Com\Token::apply( [
			'expire' => 300, // 不认证的情况下，过期时间为5分钟
		] );
		/*
		return $this->apiRequest()->apiResponse()->ofSuccess( [
			'token' => $tokenObj->getTokenStr(),
		] );
		*/
		return [
			'token' => $tokenObj->getAccessToken(),
			'apiParam' => $apiParamDto->getApiParam(),
		];
	}

}
